package com.xuanjia.xuanjiapicutrebackend.common;

import com.xuanjia.xuanjiapicutrebackend.exception.BusinessException;
import com.xuanjia.xuanjiapicutrebackend.exception.ErrorCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public BaseResponse<?> businessExceptionHandler(BusinessException businessException){
        log.info("BusinessException",businessException);
        return ResultUtils.error(businessException.getCode(),businessException.getMessage());
    }

    @ExceptionHandler(RuntimeException.class)
    public BaseResponse<?> RuntimeExceptionHandler(RuntimeException runtimeException){
        log.info("RuntimeException",runtimeException);
        return ResultUtils.error(ErrorCode.SYSTEM_ERROR,"系统错误");
    }
}
